/*
 *This file is part of SparkWeb.
 *
 *SparkWeb is free software: you can redistribute it and/or modify
 *it under the terms of the GNU Lesser General Public License as published by
 *the Free Software Foundation, either version 3 of the License, or
 *(at your option) any later version.
 *
 *SparkWeb is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU Lesser General Public License for more details.
 *
 *You should have received a copy of the GNU Lesser General Public License
 *along with SparkWeb.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.jivesoftware.spark.displayfilters
{
	
//	import com.jivesoftware.spark.managers.StringUtils;
	
	public class HTMLEscapingFilter	{
		public static function apply(string:String):String {
			if (!string || string.length == 0)
        	    return string;
	
			return escapeHTML(string);

		}
		// hack to quickly get the com.jive package to compile
		//if we use the literal regexp notation, flex gets confused and thinks the quote starts a string
		private static var quoteregex:RegExp = new RegExp('"', "g");
		private  static function escapeHTML(string:String):String {
			string = string.replace(/<br>/g, "\n");
			string = string.replace(/&/g, "&amp;");
			string = string.replace(/</g, "&lt;");
			string = string.replace(/>/g, "&gt;");
			string = string.replace(quoteregex, "&quot;");
			//	string = string.replace(/\\/g, "\\\\");
			
			return string;
			
		}
	}


}